//
//  DateHelper.swift
//  Employee
//
//  Created by swordjoy on 2017/4/6.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import Foundation
import SwiftDate



struct DateHelper {
    
    static let timeJudge: Int64 = 140000000000
  
  static func getFormatTime(timeInmillisecond: String) -> String {
    let time = timeInmillisecond.sj.int64Value
    
    guard var tempTime = time else { return "未知" }
    
    if tempTime >= timeJudge { tempTime = tempTime / 1000 }
    
    let timeInterval = TimeInterval.init(tempTime)
    let date = Date(timeIntervalSince1970: timeInterval).inLocalRegion()
    
    if date.isToday { return "今天" + date.string(custom: "HH:mm") }
    
    if date.isYesterday { return "昨天 " + date.string(custom: "HH:mm") }
    
    let twoBeforeDate = Date().add(components: [.day : -2]).inLocalRegion()
    if date.isInSameDayOf(date: twoBeforeDate) || date.year == Date().year { return date.string(custom: "MM-dd HH:mm") }
    
    return date.string(custom: "yyyy年MM月dd日 HH:mm")
  }
  
  static func getOrderCreateFormatTime(timeInmillisecond: String) -> String {
    return "创建时间 " + getFormatTime(timeInmillisecond: timeInmillisecond)
  }
  
  static func getWeekDay(date: DateInRegion) -> String {
    var week = ""
    let weekday = date.weekday
    
    switch weekday {
    case 1:
      week = "星期日 "
    case 2:
      week = "星期一 "
    case 3:
      week = "星期二 "
    case 4:
      week = "星期三 "
    case 5:
      week = "星期四 "
    case 6:
      week = "星期五 "
    case 7:
      week = "星期六 "
    default:
      break
    }
    
    return week
  }
  
}
